import type { QuestionItem } from '@/types/home'
import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'

// 定义组卷Store
export const useComposeStore = defineStore('compose', () => {
  // 待组卷题目信息
  let compose = reactive<QuestionItem[]>([])
  // 保存组卷信息，把题目加入组卷车时使用
  const setCompose = (val: QuestionItem[]) => {
    compose = val
  }
  const getCompose = () => {
    return compose
  }
  // 清理组卷信息，退出时使用
  const clearCompose = () => {
    compose = []
  }
  // 记得 return
  return {
    compose,
    setCompose,
    getCompose,
    clearCompose,
  }
})

// 定义题目详情Store
export const useDetailStore = defineStore('detail', () => {
  // 待组卷题目信息
  const detail = ref<QuestionItem>()
  // 保存组卷信息，把题目加入组卷车时使用
  const setDetail = (val: QuestionItem) => {
    detail.value = val
  }
  const getDetail = () => {
    return detail.value
  }
  // 清理组卷信息，退出时使用
  const clearDetail = () => {
    detail.value = undefined
  }
  // 记得 return
  return {
    detail,
    setDetail,
    getDetail,
    clearDetail,
  }
})
